softmax <- function(obj) {
  if (is.vector(obj)){
    exp(obj) / sum(exp(obj))
  } else if (is.matrix(obj)) {
    t(apply(obj, 1, function(x) exp(x) / sum(exp(x))))
  }
}